import { API_LIST } from '../../../Api/Api'
import { commonTableList, BuiltInData } from '../Common/common'
import { AddDataButton, ModDataButton, DelDataButton, OpenTwoRouter } from '../Common/options'

export const PushFlowConfig = async ({ url, OptionsEvent, ClientData, actionRef }) => {
    let data = {
        type: '预警管理',
        pageSize: 10,
        params: { pageIndex: 1, OrderField: 'pushFlowTypeUuid@asc,code@asc' },
        get: API_LIST()[`get${url}`],
        added: `pos${url}`,
        modify: `put${url}`,
        delete: `del${url}`,
        options: [<AddDataButton OptionsEvent={OptionsEvent} url={url} type="primary" icon="add" title="新增配置" />],
        columns: [
            commonTableList.uuid,
            {
                dataIndex: 'pushFlowTypeUuid',
                title: '流程类型',
                rules: true,
                valueType: 'select',
                valueEnum: ClientData.pushFlowTypes,
                width: 200,
            },
            { ...commonTableList.code, rules: true, hideInSearch: true },
            { ...commonTableList.tableName, title: '配置名称' },
            {
                dataIndex: 'sortId',
                title: '推送顺序',
                rules: true,
                valueType: 'inputNumber',
                hideInSearch: true,
                width: 100,
            },
            {
                dataIndex: 'pushInterval',
                title: '推送间隔时间',
                hideInSearch: true,
                rules: true,
                valueType: 'input',
                width: 120,
            },
            {
                dataIndex: 'isLastStep',
                title: '是否最后一步',
                hideInSearch: true,
                rules: true,
                valueType: 'select',
                valueEnum: BuiltInData.isYes,
                width: 120,
            },
            {
                dataIndex: 'isCyclePush',
                title: '是否循环推送',
                hideInSearch: true,
                rules: true,
                valueType: 'select',
                valueEnum: BuiltInData.isYes,
                width: 120,
            },
            {
                dataIndex: 'delayInterval',
                title: '超限推送间隔时间',
                hideInSearch: true,
                rules: true,
                valueType: 'input',
                width: 150,
            },
            // 通用部分
            {
                dataIndex: 'counter',
                title: '推送规则',
                hideInSearch: true,
                rules: true,
                valueType: 'select',
                valueEnum: BuiltInData.PushFlowConfigType,
                width: 150,
            },
            commonTableList.remark,
            commonTableList.createUserName,
            commonTableList.createTime,
            commonTableList.updateUserName,
            commonTableList.updateTime,
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 240,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    return [
                        <ModDataButton OptionsEvent={OptionsEvent} key="modify" title="修改" url={url} data={record} />,
                        <OpenTwoRouter
                            key="TwoOne"
                            title="人员配置"
                            twoTitle="推送流程人员配置"
                            modal="TableList"
                            OptionsEvent={OptionsEvent}
                            other={{
                                page: 'PushFlowConfig',
                                actionRef,
                                oneData: record,
                                header: data.columns,
                            }}
                        />,

                        <DelDataButton
                            OptionsEvent={OptionsEvent}
                            key="delete"
                            title="删除"
                            url={url}
                            uuid={record.uuid}
                        />,
                    ]
                },
            },
        ],
    }
    return data
}
